#pragma once
#include "Mesh.h"
#include "TempOutput.h"

class Solver
{
private:
	class smallHTMatrix
	{
	public:
		double values[3][3];
		int gIndex[3];

		smallHTMatrix()
		{
			for (int i = 0; i < 3; ++i)
			{
				for (int j = 0; j < 3; ++j)
				{
					values[i][j] = 0.0;
				}
			}
		}
		~smallHTMatrix()
		{
			//free(values);
		}
	};
	class bigHTMatrix
	{
	public:
		double **valMatrix;

		int size;
		bigHTMatrix(int nVertex)
		{
			size = nVertex;

			valMatrix = new double*[size];

			for (int i = 0; i < size; ++i)
			{
				valMatrix[i] = new double[size+1];
				for (int j = 0; j < size+1; ++j)
				{
					valMatrix[i][j] = 0.0;
				}
			}
		}
		~bigHTMatrix()
		{
		}
	};

	double kFactor;
	double scale;
	vector<smallHTMatrix> smallHTMatrixList;
	bigHTMatrix *result;
	TempOutput *temperatures;

	void applyFBondConditions(vector<FirstBoundary> *val);
	void applySBondConditions(vector<SecondBoundary> *val);
	smallHTMatrix createSmallHTMatrix(Element *val);
	void joinHTMatrixes(vector<smallHTMatrix> *val);
	void solveGauss();

public:
	Solver(void);
	void solve(Mesh *mesh);
	void tPrint();
	TempOutput* TempVector();
	double mod(double val);
	~Solver(void);
};